<?php

/*
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/
use  Illuminate\Support\Facades\Redis;
App::before(function($request)
{
	//
});


App::after(function($request, $response)
{
	//
});

/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/

Route::filter('auth', function()
{
	if (Auth::guest())
	{
		if (Request::ajax())
		{
			return Response::make('Unauthorized', 401);
		}
		else
		{
			return Redirect::guest('login');
		}
	}
});


Route::filter('auth.basic', function()
{
	return Auth::basic();
});

/*
|--------------------------------------------------------------------------
| Guest Filter
|--------------------------------------------------------------------------
|
| The "guest" filter is the counterpart of the authentication filters as
| it simply checks that the current user is not logged in. A redirect
| response will be issued if they are, which you may freely change.
|
*/

Route::filter('guest', function()
{
	if (Auth::check()) return Redirect::to('/');
});

/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/

Route::filter('csrf', function()
{
	if (Session::token() !== Input::get('_token'))
	{
		throw new Illuminate\Session\TokenMismatchException;
	}
});


Route::filter("in_park_sub_filit",function(){
//    Session::put('invite_code',$_REQUEST['invite_code']);
    $key=base64_encode(json_encode(array("order_id"=>Input::get("order_id"))));
    $temp = Redis::get($key);
    if($temp){
        return Lang::get("scs_error.commit_error_10012");
    }else{
        // Redis::set($key, $key,'PX', 500);
        Redis::setex( $key , 10, $key );
    }
    // $temp=Cache::get($key);
    // if($temp){
    //     return Lang::get("scs_error.commit_error_10012");
    // }else{
    //     Cache::put($key,$key,0.1);//0.3分钟
    //     $temp=Cache::get($key);
    // }
});


Route::filter("service_card_sub_filit",function(){
//    Session::put('invite_code',$_REQUEST['invite_code']);
    $key=base64_encode(json_encode(array("order_id"=>Input::get("order_id"))));
    $temp = Redis::get($key);
    if($temp){
        return Lang::get("scs_error.commit_error_10012");
    }else{
        // Redis::set($key, $key,'PX', 500);
        Redis::setex( $key , 10, $key );
    }
    // $temp=Cache::get($key);
    // if($temp){
    //     return Lang::get("scs_error.commit_error_10012");
    // }else{
    //     Cache::put($key,$key,0.003);//0.3分钟
    // }
});

Route::filter("return_im_filit",function(){
//    Session::put('invite_code',$_REQUEST['invite_code']);
    $key=base64_encode(json_encode(array("return_order_id"=>Input::get("return_order_id"))));
    $temp = Redis::get($key);
    if($temp){
        return Lang::get("scs_error.commit_error_10012");
    }else{
        // Redis::set($key, $key,'PX', 500);
        Redis::setex( $key , 10, $key );
    }
    // $temp=Cache::get($key);
    // if($temp){
    //     return Lang::get("scs_error.commit_error_10012");
    // }else{
    //     Cache::put($key,$key,0.003);//0.3分钟
    // }
});

Route::filter("repeated_submission",function(){
//    Session::put('invite_code',$_REQUEST['invite_code']);
    $key=base64_encode(json_encode(array("order_id"=>Input::get("order_id"),"moo_ids"=>Input::get("moo_ids"),"ids"=>Input::get("ids"))));
    $temp = Redis::get($key);
    if($temp){
        return Lang::get("scs_error.commit_error_10012");
    }else{
        // Redis::set($key, $key,'PX', 500);
        Redis::setex( $key , 10, $key );
    }
    // $temp=Cache::get($key);
    // if($temp){
    //     return Lang::get("scs_error.commit_error_10012");
    // }else{
    //     Cache::put($key,$key,0.003);
    // }
});

Route::filter("repeated_submission_login",function(){
    $key=base64_encode(json_encode(array("phone"=>Input::get("phone"),"check_code"=>Input::get("check_code"))));
    /*
    $temp=Cache::get($key);
    if($temp){
        return Lang::get("scs_error.commit_error_10012");
    }else{
        Cache::put($key,$key,0.03);
    }*/
    $temp = Redis::get($key);
    if($temp){
        return Lang::get("scs_error.commit_error_10012");
    }else{
        Redis::set($key, $key,'PX', 500);
    }
});

Route::filter("repeated_receive_coupons",function(){
    $key=base64_encode(json_encode(array("car_no"=>Input::get("car_no"))));
    // $temp=Cache::get($key);
    $temp = Redis::get($key);
    if($temp){
        return Lang::get("scs_error.commit_error_10012");
    }else{
        Redis::set($key, $key,'PX', 500);
    }
});

Route::filter("repeated_receive_coupons_two",function(){
    $key=base64_encode(json_encode(array("activity_id"=>Input::get("activity_id"),"phone"=>Input::get("phone"))));
    $temp = Redis::get($key);
    if($temp){
        return Lang::get("scs_error.commit_error_10012");
    }else{
        Redis::set($key, $key,'PX', 5000);
    }
});


Route::filter("filit_all_area_filt",function(){
    $key=base64_encode(json_encode(Input::all()));
    $temp = Redis::get($key);
    if($temp){
        return Lang::get("scs_error.commit_error_10012");
    }else{
        Redis::set($key, $key,'PX', 500);
    }
    // $temp=Cache::get($key);
    // if($temp){
    //     return Lang::get("scs_error.commit_error_10012");
    // }else{
    //     Cache::put($key,$key,0.05);
    // }
});

Route::filter("pmssce_submission",function(){
//    Session::put('invite_code',$_REQUEST['invite_code']);
    Log::info(11111);
    $key=base64_encode(json_encode(array("plan_code"=>Input::get("plan_code"))));
    $temp = Redis::get($key);
    if($temp){
        return Lang::get("scs_error.commit_error_10012");
    }else{
        // Redis::set($key, $key,'PX', 500);
        Redis::setex( $key , 10, $key );
    }
    
    // $temp=Cache::get($key);
    // if($temp){
    //     return Lang::get("scs_error.commit_error_10012");
    // }else{
    //     Cache::put($key,$key,0.003);
    // }
});


Route::filter("repeated_receive_coupons_new",function(){
//    Session::put('invite_code',$_REQUEST['invite_code']);
    $key=base64_encode(json_encode(array("phone"=>Input::get("phone"))));
    $temp = Redis::get($key);
    if($temp){
        return Lang::get("scs_error.commit_error_10012");
    }else{
        // Redis::set($key, $key,'PX', 500);
        Redis::setex( $key , 10, $key );
    }
    // $temp=Cache::get($key);
    // if($temp){
    //     return Lang::get("scs_error.commit_error_10012");
    // }else{
    //     Cache::put($key,$key,0.003);
    // }
});

Route::filter("car_wash_submission",function(){
//    Session::put('invite_code',$_REQUEST['invite_code']);
    $key=base64_encode(json_encode(array("car_no"=>Input::get("car_no"),"type"=>"car_wash")));
    $temp = Redis::get($key);
    if($temp){
        return Lang::get("scs_error.commit_error_10012");
    }else{
        // Redis::set($key, $key,'PX', 500);
        Redis::setex( $key , 10, $key );
    }
    // $temp=Cache::get($key);
    // if($temp){
    //     return Lang::get("scs_error.commit_error_10012");
    // }else{
    //     Cache::put($key,$key,0.003);
    // }
});